package cn.linran.feignclient;

import cn.linran.domain.User;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * UserFeign的熔断工厂类
 */
@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {

    /**
     * 熔断托底方法
     * @param throwable
     * @return
     */
    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public User getById(Long id) {
                return new User(-1L, "触发熔断", "服务不可用，请稍后重试！");
            }
        };
    }
}